
import { defineStore } from 'pinia';
import { judgeEnterpriseRoleFunc } from '@/utils/roleList.js';

export const enterpriseRole = defineStore('enterpriseRole', {
    state: () => ({
        roleData: {
            rank: 0,
        },
        roleDataMenu: {//用于菜单
            rank: 0,
        },
        enterpriseRoleListAll: [
            { name: "管理员", value: "manage" },
            { name: "可编辑", value: "editor" },
            { name: "可查看", value: "query" },
        ],//企业全部权限
        enterpriseMyRoleList: [],//我拥有的权限列表
        enterpriseMyParentRoleList: [],//父级文件权限列表,用与新建和上传
    }),
    // mutations: {
    //     SET_ROLE(state, { params, type }) {
    //         if (type == 'parent') {
    //             state.enterpriseMyParentRoleList = judgeEnterpriseRoleFunc(params)
    //         } else {
    //             state.enterpriseMyRoleList = judgeEnterpriseRoleFunc(params)
    //         }
    //         // console.log(state.enterpriseMyRoleList,'state.enterpriseMyRoleList');
    //     }
    // },
    actions: {
        /**获取企业权限-保存父文件的权限,用于上传和新建
         * @param {object} rootGetters 获取全局的getters 参数
         * @param {object} params 当前文件夹或者文件信息
         * @param {string} type current/或者不传:当前级   parent:父级权限
         */
        getEnteroriseFileRole(params:any) {
            return new Promise((resolve, reject) => {
                //如果在第一层,只有超级管理员和企业文档管理员才能分配权限和新建文件夹
                let user:any = null
                if (params.id == 1) {//判断是否在第一层
                    if (user.id == 1 || user.roles.findIndex(item => item.name == '企业文档管理员') !== -1) {
                        // commit('SET_ROLE', { params: "manage", type: type })
                    } else {
                        // state.enterpriseMyParentRoleList = judgeEnterpriseRoleFunc("")
                        // commit('SET_ROLE', { params: "", type: type })
                        this.enterpriseMyRoleList = judgeEnterpriseRoleFunc(params)
                    }
                } else {
                    this.enterpriseMyRoleList = judgeEnterpriseRoleFunc(params.perm)
                    // commit('SET_ROLE', { params: params.perm, type: type })
                }
                // resolve(state.enterpriseMyParentRoleList)
            })
        },
    }
})
